/*****************************************************
 * jr generated file
 ****************************************************/
import java.rmi.*;
import java.util.LinkedList;
import java.util.List;
import edu.ucdavis.jr.*;
import edu.ucdavis.jr.jrx.*;
import java.rmi.*;
import java.io.Serializable;

public class InOp_DiffusionCountProcessorXbooleanTovoid_impl
  extends Op_impl
  implements InOp_DiffusionCountProcessorXbooleanTovoid
{
    protected List<Recv_DiffusionCountProcessorXbooleanTovoid> msg_list;
    protected List<Recv_DiffusionCountProcessorXbooleanTovoid> wait_list;
    protected InLock theLock;
     public DiffusionCountProcessor val;
    public InOp_DiffusionCountProcessorXbooleanTovoid_impl() throws java.rmi.RemoteException
    {
	this(true, true);
    }
    public static InOp_DiffusionCountProcessorXbooleanTovoid_impl create()
    {
	try {
	return new InOp_DiffusionCountProcessorXbooleanTovoid_impl();
	} catch (RemoteException e) { throw new edu.ucdavis.jr.jrCommunicationException(e); }
    }
    public InOp_DiffusionCountProcessorXbooleanTovoid_impl(boolean reg) throws java.rmi.RemoteException
    {
	this(reg, true);
    }
    public InOp_DiffusionCountProcessorXbooleanTovoid_impl(boolean reg, boolean queue) throws java.rmi.RemoteException
    {
	super(reg);
	if (queue)
	{
	    msg_list = new LinkedList<Recv_DiffusionCountProcessorXbooleanTovoid>();
	    wait_list = new LinkedList<Recv_DiffusionCountProcessorXbooleanTovoid>();
	}
	theLock = new InLock_impl(jrvm.vmName, false);
    }
    public Cap_voidTovoid cocall(long JRtimestamp, DiffusionCountProcessor arg0, boolean arg1) throws java.rmi.RemoteException

    {
      jrvm.ariseAndReceive(); // from caller
      try
      {
	Op_voidTovoid.JRProxyOp op = new Op_voidTovoid.JRProxyOp(new InOp_voidTovoid_impl());
	Cap_voidTovoid retOp =
	    new Cap_voidTovoid (op);
	this.send(JRtimestamp, op, null, null, arg0, arg1);
	return retOp;
      }
      finally
      {
	jrvm.sendAndDie(); // to caller
      }
    }
    public Cap_voidTovoid cocall(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, Cap_voidTovoid fretOp, DiffusionCountProcessor arg0, boolean arg1) throws java.rmi.RemoteException
    {
      jrvm.ariseAndReceive(); // from caller
      try
      {
	Op_voidTovoid.JRProxyOp op = new Op_voidTovoid.JRProxyOp(new InOp_voidTovoid_impl());
	Cap_voidTovoid retOp =
	    new Cap_voidTovoid (op);
	this.send(JRtimestamp, op, fretOp, handler, null, arg0, arg1);
	return retOp;
      }
      finally
      {
	jrvm.sendAndDie(); // to caller
      }
    }
    public void call(long JRtimestamp, DiffusionCountProcessor arg0, boolean arg1) throws java.rmi.RemoteException

    {
      jrvm.ariseAndReceive(); // from caller
      try
      {
	Op_voidTovoid.JRProxyOp retOp =
	    new Op_voidTovoid.JRProxyOp(new InOp_voidTovoid_impl(false));
	this.send(JRtimestamp, retOp, null, null, arg0, arg1);
	jrvm.sendAndDie(); // to recv
	Recv_voidTovoid ret;
	try {
	    ret = retOp.recv();
	} finally {
	    jrvm.ariseAndReceive(); // from recv
	}
	retOp.delete(false);
	// check for exception
	if (ret.thrownException != null)
	{
	    // catch all
	    throw new jrRuntimeError("Unhandled exception: " + ret.thrownException.toString());
	}
	return;
      }
      finally
      {
	jrvm.sendAndDie(); // to caller
      }
    }
    public void send(long JRtimestamp, DiffusionCountProcessor arg0, boolean arg1) throws java.rmi.RemoteException
    {
	send(JRtimestamp, null, null, null, arg0, arg1);
    }
    public void send(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, DiffusionCountProcessor arg0, boolean arg1) throws java.rmi.RemoteException
    {
	send(JRtimestamp, null, handler, null, arg0, arg1);
    }
    public void send(long JRtimestamp, Exception thrown) throws java.rmi.RemoteException
    {
	send(JRtimestamp, (Op_voidTovoid.JRProxyOp) null, null, thrown, (DiffusionCountProcessor)null, (boolean)false);
    }
    public void send(long JRtimestamp, Op_voidTovoid.JRProxyOp retOp, 
edu.ucdavis.jr.RemoteHandler handler, Exception thrown, DiffusionCountProcessor arg0, boolean arg1) throws java.rmi.RemoteException
    {
	Recv_DiffusionCountProcessorXbooleanTovoid newmsg =
	    new Recv_DiffusionCountProcessorXbooleanTovoid(jrvm.setTimestamp(JRtimestamp), retOp, handler, thrown, arg0, arg1);
	synchronized (this)
	{
	  synchronized (this.wait_list)
	  {
	    this.wait_list.add(newmsg);
	  }
	}
	boolean lockp = this.theLock.lock_or_register(this);
	synchronized (this)
	{
	    if(lockp) // this inOp successfully locked the equiv. class
	    {
		synchronized (this.wait_list)
		{
		    synchronized (this.msg_list)
		    {
			while (this.wait_list.size() != 0)
			{
			    this.msg_list.add((Recv_DiffusionCountProcessorXbooleanTovoid)this.wait_list.remove(0));
			}
		    }
		}
	    }
	}
	if(lockp)
	{
	    // awaken a waiting process (pass the baton)
	    this.theLock.unlockMes();
	}
    }
    public void send(long JRtimestamp, Op_voidTovoid.JRProxyOp retOp, Cap_voidTovoid fretOp, 
edu.ucdavis.jr.RemoteHandler handler, Exception thrown, DiffusionCountProcessor arg0, boolean arg1) throws java.rmi.RemoteException
    {
	Recv_DiffusionCountProcessorXbooleanTovoid newmsg =
	    new Recv_DiffusionCountProcessorXbooleanTovoid(jrvm.setTimestamp(JRtimestamp), retOp, fretOp, handler, thrown, arg0, arg1);
	synchronized (this)
	{
	  synchronized (this.wait_list)
	  {
	    this.wait_list.add(newmsg);
	  }
	}
	boolean lockp = this.theLock.lock_or_register(this);
	synchronized (this)
	{
	    if(lockp) // this inOp successfully locked the equiv. class
	    {
		synchronized (this.wait_list)
		{
		    synchronized (this.msg_list)
		    {
			while (this.wait_list.size() != 0)
			{
			    this.msg_list.add((Recv_DiffusionCountProcessorXbooleanTovoid)this.wait_list.remove(0));
			}
		    }
		}
	    }
	}
	if(lockp)
	{
	    // awaken a waiting process (pass the baton)
	    this.theLock.unlockMes();
	}
    }
	public Cap_voidTovoid cosend(long JRtimestamp, DiffusionCountProcessor arg0, boolean arg1) throws java.rmi.RemoteException
    {
	return cosend(JRtimestamp, null, null, null, arg0, arg1);
    }
    public Cap_voidTovoid cosend(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, DiffusionCountProcessor arg0, boolean arg1) throws java.rmi.RemoteException
    {
	return cosend(JRtimestamp, null, handler, null, arg0, arg1);
    }
    public Cap_voidTovoid cosend(long JRtimestamp, Exception thrown) throws java.rmi.RemoteException
    {
	return cosend(JRtimestamp, null, null, thrown, (DiffusionCountProcessor)null, (boolean)false);
    }
    public Cap_voidTovoid cosend(long JRtimestamp, Op_voidTovoid.JRProxyOp retOp, 
edu.ucdavis.jr.RemoteHandler handler, Exception thrown, DiffusionCountProcessor arg0, boolean arg1) throws java.rmi.RemoteException
    {
	Op_voidTovoid.JRProxyOp op = new Op_voidTovoid.JRProxyOp(new InOp_voidTovoid_impl());
	op.send(JRtimestamp);
	Recv_DiffusionCountProcessorXbooleanTovoid newmsg =
	    new Recv_DiffusionCountProcessorXbooleanTovoid(jrvm.setTimestamp(JRtimestamp), retOp, handler, thrown, arg0, arg1);
	synchronized (this)
	{
	  synchronized (this.wait_list)
	  {
	    this.wait_list.add(newmsg);
	  }
	}
	boolean lockp = this.theLock.lock_or_register(this);
	synchronized (this)
	{
	    if(lockp) // this inOp successfully locked the equiv. class
	    {
		synchronized (this.wait_list)
		{
		    synchronized (this.msg_list)
		    {
			while (this.wait_list.size() != 0)
			{
			    this.msg_list.add((Recv_DiffusionCountProcessorXbooleanTovoid)this.wait_list.remove(0));
			}
		    }
		}
	    }
	}
	if(lockp)
	{
	    // awaken a waiting process (pass the baton)
	    this.theLock.unlockMes();
	}
	return new Cap_voidTovoid(op);
    }
    public Recv_DiffusionCountProcessorXbooleanTovoid recv() throws java.rmi.RemoteException
    {
	Recv_DiffusionCountProcessorXbooleanTovoid ret;
	boolean empty, exception = false;
	jrvm.ariseAndReceive(); // from caller
	try
	{
	    exception = true;
	    jrvm.sendAndDie(); // to lock
	    this.theLock.lock();
	    jrvm.ariseAndReceive(); // from lock
	    exception = false;

	    while (true)
	    {
		empty = false;
		synchronized (this.msg_list)
		{
		    if (this.msg_list.size() == 0)
			empty = true;
		}
		if (empty)
		{
		    exception = true;
		    jrvm.sendAndDie(); // to lock
		    this.theLock.waitOnLock();
		    jrvm.ariseAndReceive(); // from lock
		    exception = false;
		}
		else
		    break;
	    }
	    try
	    {
		ret = (Recv_DiffusionCountProcessorXbooleanTovoid)this.msg_list.remove(0);
	    }
	    catch (IndexOutOfBoundsException doh)
	    {
		exception = true;
		jrvm.sendAndDie(); // to lock
		this.theLock.unlock();
		jrvm.ariseAndReceive(); // from lock
		exception = false;
		throw new jrRuntimeError("Unexpected empty operation!");
	    }
	    catch (Exception doh)
	    {
		exception = true;
		jrvm.sendAndDie(); // to lock
		this.theLock.unlock();
		jrvm.ariseAndReceive(); // from lock
		exception = false;
		throw new jrRuntimeError("Exception while receiving from an operation!");
	    }
	    // release the lock
	    exception = true;
	    jrvm.sendAndDie(); // to lock
	    this.theLock.unlock();
	    jrvm.ariseAndReceive(); // from lock
	    exception = false;
	    if (ret == null)
		throw new jrRuntimeError("Null receive node!");
	    return ret;
	}
	finally
	{
	    if (!exception)
	    {
		jrvm.sendAndDie(); // to caller
	    }
	}
    }
    public synchronized void deliverPendingMessages()
	throws java.rmi.RemoteException
    {
	// the equiv class should already be locked
	try
	{
	  synchronized (this.wait_list)
	  {
	   synchronized (this.msg_list)
	   {
	    while (this.wait_list.size() != 0)
	    {
		this.msg_list.add((Recv_DiffusionCountProcessorXbooleanTovoid)this.wait_list.remove(0));
	    }
	   }
	  }
	}
	catch (IndexOutOfBoundsException doh)
	{
	    throw new jrRuntimeError("Unexpected empty operation!");
	}
	catch (Exception doh)
	{
	    throw new jrRuntimeError("Exception while sending to an operation!");
	}
    }
    public synchronized int length() throws java.rmi.RemoteException
    {
	int i;
	if (msg_list == null) return 0;
	return msg_list.size();
    }
    public synchronized InLock getLock() throws java.rmi.RemoteException
    {
	return this.theLock;
    }
    public synchronized long getFirstTime() throws java.rmi.RemoteException
    {
	if (this.msg_list.size() != 0)
	    return ((Recv_DiffusionCountProcessorXbooleanTovoid)this.msg_list.get(0)).timestamp;
	return -1;
    }
    public synchronized InOpIterator elements() throws java.rmi.RemoteException
    {
	return new InOpIterator_impl(new InOpIteratorRemote_impl(msg_list));
    }
    public boolean isRemote(String site) throws java.rmi.RemoteException
    {
	return (jrvm.thisVM.getName().compareTo(site) != 0);
    }
}
